<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>编辑供应商</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" href="admin/css/common.css" type="text/css" />
<link rel="stylesheet" href="admin/css/provider.css" type="text/css" />
<script type="text/javascript" src="admin/js/province-city.js"></script>
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/jwidget_1.0.0-min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript">
	var s = [ "s1", "s2" ];
	var opt0 = [ "省份", "地级市" ];
	function setup() {
		for (i = 0; i < s.length - 1; i++)
			document.getElementById(s[i]).onchange = new Function("change("
					+ (i + 1) + ")");
		change(0);

		var t = new Date();
		var y = t.getFullYear();
		for (i = 1900; i <= y; i++)
			document.getElementById("year_select").options.add(new Option(""
					+ i, i));
		for (i = 1; i <= 12; i++)
			document.getElementById("month_select").options.add(new Option(""
					+ i, i));

		var currentYear = document.getElementById("hiddenyear").value;
		var currentMonth = document.getElementById("hiddenmonth").value;
		//alert("" + currentYear);
		document.getElementById("year_select").value = currentYear;
		document.getElementById("month_select").value = currentMonth;

		var currentProvince = document.getElementById("hiddenprovince").value;
		var currentCity = document.getElementById("hiddencity").value;
		//alert("" + currentYear);
		document.getElementById("s1").value = currentProvince;
		change(1);
		document.getElementById("s2").value = currentCity;

	}

	//邮箱判断正则表达式
	function isEmail(yx) {
		if (yx == "")
			return true;
		var reyx = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
		return (reyx.test(yx));
	}

	//判断是否为空
	function check() {

		$('#nameTip').text("");
		$('#shortableTip').text("");
		$('#sTip').text("");
		$('#addressTip').text("");
		$('#registercapitalTip').text("");
		$('#staffsizeTip').text("");
		$('#factoryareaTip').text("");
		$('#bigslabTip').text("");
		$('#rawStoneTip').text("");
		$('#standardslabTip').text("");
		$('#phoneTip').text("");
		$('#faxTip').text("");
		$('#emailTip').text("");

		var phoneflag = 0;
		var phonestring = "";
		$('.phone').each(function() {
			if (isNaN($(this).val()) == true)
				phoneflag = 0;
			else if ($(this).val() != "")
				phonestring += $(this).val() + "#";
		});

		var faxflag = 0;
		var faxstring = "";
		$('.fax').each(function() {
			if (isNaN($(this).val()))
				faxflag = 1;
			else if ($(this).val() != "")
				faxstring += $(this).val() + "#";
		});

		var emailflag = 0;
		var emailstring = "";
		$('.email').each(function() {
			if (!isEmail($(this).val()))
				emailflag = 1;
			else if ($(this).val() != "")
				emailstring += $(this).val() + "#";
		});

		var websitestring = "";
		$('.website').each(function() {
			if ($(this).val() != "")
				websitestring += $(this).val() + "#";
		});

		if ($('#name').val() == "") {
			$('#nameTip').text("*名字不能为空");
			$('#name').focus();
			return false;
		} else if (phoneflag == 1) {
			$('#phoneTip').text("*电话应为数字");
			$('#phone').focus();
			return false;
		} else if (faxflag == 1) {
			$('#faxTip').text("*传真应为数字");
			$('#fax').focus();
			return false;
		} else if (emailflag == 1) {
			$('#emailTip').text("*邮箱格式不正确");
			$('#email').focus();
			return false;
		} else if ($('#nameFlag').val() != "yes") {
			$('#nameTip').text("*名字已经存在");
			$('#name').focus();
			return false;
		} else if ($('#shortable').val() == "") {
			$('#shortableTip').text("*缩写不能为空");
			$('#shortable').focus();
			return false;
		} else if ($('#s1').val() == "省份" || $('#s2').val() == "地级市") {
			$('#sTip').text("*请选择好省、市");
			$('#s1').focus();
			return false;
		} else if ($('#address').val() == "") {
			$('#addressTip').text("*地址不能为空");
			$('#address').focus();
			return false;
		} else if (isNaN($('#registerCapital').val())) {
			$('#registercapitalTip').text("*注册资金应为数字");
			$('#registerCapital').focus();
			return false;
		} else if (isNaN($('#staffSize').val())) {
			$('#staffsizeTip').text("*人员规模应为数字");
			$('#staffSize').focus();
			return false;
		} else if (isNaN($('#factoryArea').val())) {
			$('#factoryareaTip').text("*厂房面积应为数字");
			$('#factoryArea').focus();
			return false;
		} else if (isNaN($('#bigSlab').val())) {
			$('#bigslabTip').text("*应为数字");
			$('#bigSlab').focus();
			return false;
		} else if (isNaN($('#rawStone').val())) {
			$('#rawstoneTip').text("*应为数字");
			$('#rawStone').focus();
			return false;
		} else if (isNaN($('#standardSlab').val())) {
			$('#standardslabTip').text("*应为数字");
			$('#standardSlab').focus();
			return false;
		} else {
			if (phonestring != "")
				$('#phonelist').val(phonestring);
			if (faxstring != "")
				$('#faxlist').val(faxstring);
			if (emailstring != "")
				$('#emaillist').val(emailstring);
			if (websitestring != "")
				$('#websitelist').val(websitestring);
		}
		return true;
	}

	function checkName() {
		$('#nameFlag').val("no");
		if ($("#name").val() != "") {
			var params = {
				providerName : $("#name").val(),
				flag : "update",
				providerId : $('#providerId').val()
			};
			jQuery.post("checkNameExist.action", params, callbackFunc, "json");
		}
	}
	function callbackFunc(data) {
		if (data.existFlag > 0) {
			$('#nameTip').html('<font color="red">*名字已经存在</font>');
			$('#nameFlag').val("no");
		} else {
			$('#nameTip').html('<font color="green">名字可以使用</font>');
			$('#nameFlag').val("yes");
		}
	}

	function addPhone() {
		$('#td_phone').append("<input type=\"text\" class=\"phone\" />");
		$('#but_phone').remove();
		$('#phoneTip').remove();
		$('#td_phone')
				.append(
						"<input id=\"but_phone\" type=\"button\" value=\"添加\" onclick=addPhone()></input><span class=\"tip\" id=\"phoneTip\"></span>");
	}
	function addFax() {
		$('#td_fax').append("<input type=\"text\" class=\"fax\" />");
		$('#but_fax').remove();
		$('#faxTip').remove();
		$('#td_fax')
				.append(
						"<input id=\"but_fax\" type=\"button\" value=\"添加\" onclick=addFax()></input><span class=\"tip\" id=\"faxTip\"></span>");
	}
	function addEmail() {
		$('#td_email').append("<input type=\"text\" class=\"email\" />");
		$('#but_email').remove();
		$('#emailTip').remove();
		$('#td_email')
				.append(
						"<input id=\"but_email\" type=\"button\" value=\"添加\" onclick=addEmail()></input><span class=\"tip\" id=\"emailTip\"></span>");
	}
	function addWebsite() {
		$('#td_website').append("<input type=\"text\" class=\"website\" />");
		$('#but_website').remove();
		$('#websiteTip').remove();
		$('#td_website')
				.append(
						"<input id=\"but_website\" type=\"button\" value=\"添加\" onclick=addWebsite()></input><span class=\"tip\" id=\"websiteTip\"></span>");
	}

	var resetGPS;
	function addMap() {
		if ($('#gps_address').val() == "在地图上标识") {
			$('#map_tr').css("display", "block");
			$('#gps_address').val("重置坐标");
			resetGPS = $('#lnglat').val();
			loadMap();
		} else {
			$('#lnglat').val(resetGPS);
			loadMap();
		}
	}

	function loadMap() {
		map = new BMap.Map("container");
		var point;
		//默认中心
		if (resetGPS != "") {
			var position = resetGPS.split("，");
			point = new BMap.Point(position[0], position[1]);
		} else
			point = new BMap.Point(118.18267822265625, 24.781747337815794);

		map.centerAndZoom(point, 11);
		map.addControl(new BMap.NavigationControl());//启动鱼骨插件
		map.addControl(new BMap.OverviewMapControl());//启动缩略图
		map.enableScrollWheelZoom(); // 启用滚轮放大缩小。
		map.enableKeyboard(); // 启用键盘操作。
		var marker = new BMap.Marker(point);
		map.addOverlay(marker);
		marker.enableDragging(true); // 设置标注可拖拽

		marker.addEventListener("dragend", function() {
			GPSPoint = marker.getPosition();
			var GPS = GPSPoint.lng + "，" + GPSPoint.lat;
			$('#lnglat').val(GPS);
		});

	}
</script>
</head>
<body onload="setup()">
	<div id="provider_zone">
		<form action="provider/updateProvider.action?type=text" method="post"
			enctype="multipart/form-data" onsubmit="return check();">
			<table width="99%" border="0" align="center" cellpadding="3"
				cellspacing="1" class="table_style">
				<tr>
					<td class="left_title_1">供应商名字</td>
					<td><input type="text" name="provider.name" id="name"
						value="${provider.name }" onblur="checkName()" /> <span
						class="tip" id="nameTip"></span> <input type="hidden"
						id="nameFlag" value="yes" /></td>
				</tr>
				<tr>
					<td class="left_title_2">检索缩写</td>
					<td><input type="text" name="provider.shortable"
						id="shortable" maxlength="1" value="${provider.shortable }">
						<span class="tip" id="shortableTip"></span></td>
				</tr>
				<tr>
					<td class="left_title_2">省、市</td>
					<td><select id="s1" name="provider.province" class="address"><option
								value="${provider.province }">${provider.province }</option>
					</select> <select id="s2" name="provider.city" class="address"><option
								value="${provider.city }">${provider.city }</option>
					</select> <span class="tip" id="sTip"></span> <input type="hidden"
						id="hiddenprovince" value="${provider.province}" /> <input
						type="hidden" id="hiddencity" value="${provider.city}" /></td>
				</tr>
				<tr>
					<td class="left_title_1">公司地址</td>
					<td><input class="long-input" type="text"
						name="provider.address" id="address" value="${provider.address }"><input
						id="gps_address"
						style="background:#ffffff;color:#73938e; border:0;cursor:hand;"
						type="button" value="在地图上标识" onclick=addMap()></input> <span
						class="tip" id="addressTip"></span></td>
				</tr>
				<tr style="display:none" id="map_tr">
					<td class="left_title_1">地图定位</td>
					<td>
						<div>
							<span>经纬度：</span> <input name="provider.lnglat"
								value="${provider.lnglat }"
								style="background:#ffffff;color:#73938e; border:0;"
								class="long-input" type="text" id="lnglat" readonly="true" />
						</div>
						<div>
							<span class="tip">请将标注拖曳至公司所在位置</span>
						</div>
						<div style="width:500px;height:400px;border:1px solid gray;"
							id="container"></div></td>
				</tr>
				<tr>
					<td class="left_title_2">注册资金</td>
					<td><input type="text" name="provider.registerCapital"
						id="registerCapital" value="${provider.registerCapital }">
						<span>万元</span><span class="tip" id="registercapitalTip"></span></td>
				</tr>
				<tr>
					<td class="left_title_1">成立时间</td>
					<td><select id="year_select" name="year" class="address">
					</select>年<input type="hidden" id="hiddenyear" value="${year}" /> <select
						id="month_select" name="month" class="address">
					</select>月<input type="hidden" id="hiddenmonth" value="${month}" />
					</td>
					<!-- <td><input class="long-input" type="text"
						name="provider.foundationTime" id="foundationTime"
						value="${provider.foundationTime }"> <span class="tip"
						id="foundationtimeTip"></span></td> -->
				</tr>
				<tr>
					<td class="left_title_2">人员规模</td>
					<td><input type="text" name="provider.staffSize"
						id="staffSize" value="${provider.staffSize }"> <span>人</span><span
						class="tip" id="staffsizeTip"></span></td>
				</tr>
				<tr>
					<td class="left_title_1">厂房面积</td>
					<td><input type="text" name="provider.factoryArea"
						id="factoryArea" value="${provider.factoryArea }"> <span>平方米</span><span
						class="tip" id="factoryareaTip"></span></td>
				</tr>
				<tr>
					<td class="left_title_2">加工设备</td>
					<td><input type="text" name="provider.equipment"
						id="equipment" value="${provider.equipment }"> <span
						class="tip" id="equipmentTip"></span></td>
				</tr>
				<tr>
					<td class="left_title_1" rowspan="3">年加工能力</td>
					<td><span>大板&nbsp;&nbsp;&nbsp;</span><input type="text"
						name="provider.bigSlab" id="bigSlab" value="${provider.bigSlab }">
						<span>平方米</span> <span class="tip" id="bigslabTip"></span></td>
				</tr>
				<tr>
					<td><span>荒料&nbsp;&nbsp;&nbsp;</span><input type="text"
						name="provider.rawStone" id="rawStone"
						value="${provider.rawStone }"> <span>平方米</span> <span
						class="tip" id="rawstoneTip"></span></td>
				</tr>
				<tr>
					<td><span>规格板&nbsp;&nbsp;&nbsp;</span><input type="text"
						name="provider.standardSlab" id="standardSlab"
						value="${provider.standardSlab }"> <span>平方米</span> <span
						class="tip" id="standardslabTip"></span></td>
				</tr>
				<tr>
					<td class="left_title_2" rowspan="6">联系方式</td>
					<td><span>联系人</span><input type="text"
						name="provider.contactPerson" id="contactPerson"
						value="${provider.contactPerson }">
					</td>
				</tr>
				<tr>
					<td><span>职务&nbsp;&nbsp;&nbsp;</span><input type="text"
						name="provider.duty" id="duty" value="${provider.duty }">
					</td>
				</tr>
				<tr>
					<td id='td_phone'><span>电话&nbsp;&nbsp;&nbsp;</span> <s:iterator
							value="phoneList" var="item" status="status">
							<input type="text" id="phone" class="phone"
								value="<s:property value="#item" />" />
						</s:iterator> <input id="but_phone" type="button" value="添加" onclick=addPhone()></input>
						<span class="tip" id="phoneTip"></span> <input type="text"
						id='phonelist' style="display:none" name="provider.phone">
					</td>
				</tr>
				<tr>
					<td id='td_fax'><span>传真&nbsp;&nbsp;&nbsp;</span> <s:iterator
							value="faxList" var="item" status="status">
							<input type="text" id="fax" class="fax"
								value="<s:property value="#item" />" />
						</s:iterator> <input id="but_fax" type="button" value="添加" onclick=addFax()></input>
						<span class="tip" id="faxTip"></span> <input type="text"
						id='faxlist' style="display:none" name="provider.fax"></td>
				</tr>
				<tr>
					<td id='td_website'><span>网址&nbsp;&nbsp;&nbsp;</span> <s:iterator
							value="websiteList" var="item" status="status">
							<input type="text" id="website" class="website"
								value="<s:property value="#item" />" />
						</s:iterator> <input id="but_website" type="button" value="添加"
						onclick=addWebsite()></input> <span class="tip" id="websiteTip"></span>
						<input type="text" id='websitelist' style="display:none"
						name="provider.webSite"></td>
				</tr>
				<tr>
					<td id='td_email'><span>邮箱&nbsp;&nbsp;&nbsp;</span> <s:iterator
							value="emailList" var="item" status="status">
							<input type="text" id="email" class="email"
								value="<s:property value="#item" />" />
						</s:iterator> <input id="but_email" type="button" value="添加" onclick=addEmail()></input>
						<span class="tip" id="emailTip"></span> <input type="text"
						id='emaillist' style="display:none" name="provider.email">
					</td>
				</tr>
				<tr>
					<td class="left_title_1">概要介绍</td>
					<td><input class="long-input" type="text"
						name="provider.shortDescription" id="shortDescription"
						value="${provider.shortDescription 	 }">
					</td>
				</tr>
				<tr>
					<td class="left_title_2">主营业务</td>
					<td><input class="long-input" type="text"
						name="provider.product" id="product" value="${provider.product }">
					</td>
				</tr>
				<tr>
					<td class="left_title_1">其他介绍（获奖情况等）</td>
					<td><input class="long-input" type="text"
						name="provider.other" id="other" value="${provider.other }">
					</td>
				</tr>
				<!-- <tr>
					<td class="left_title_1">供应商规模</td>
					<td><input class="short-input" type="text"
						name="provider.state" id="state" value="${provider.state }">
					</td>
				</tr> -->
				<tr>
					<td colspan="2" style="padding-left: 530px;"><input
						type="submit" class="input-submit" value="更新信息" /> <input
						type="hidden" value="${providerId }" name="providerId"
						id="providerId" /> <input type="hidden" value="${providerId }"
						name="provider.id" /></td>
				</tr>

			</table>
		</form>
	</div>
</body>
</html>
